#define _CRT_SECURE_NO_WARNINGS 1


#include<iostream>

using namespace std;

bool Func(int n)
{
	while (n)
	{
		if (n % 10 == 2)
		{
			return false;
		}
		n /= 10;
	}
	return true;
}

int main()
{
	int n = 0;
	cin >> n;
	int count = 0;
	for (int i = 1; i <= n; i++)
	{
		if (Func(i))
		{
			count++;
		}
	}
	cout << count << endl;

	return 0;
}